package cn.jd.org.service.impl;

import cn.jd.basic.service.impl.BasicServiceImpl;
import cn.jd.org.domain.Systemdictionarydetail;
import cn.jd.org.domain.Systemdictionarytype;
import cn.jd.org.mapper.SystemdictionarydetailMapper;
import cn.jd.org.mapper.SystemdictionarytypeMapper;
import cn.jd.org.service.SystemdictionarydetailService;
import cn.jd.org.service.SystemdictionarytypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class SystemdictionarytypeImpl extends BasicServiceImpl<Systemdictionarytype> implements SystemdictionarytypeService {
    @Autowired
    private SystemdictionarytypeMapper mapper;
    @Autowired
    private SystemdictionarydetailMapper Systemdictionarydetailmapper;
    @Override
    public List<Systemdictionarydetail> findSystemdictionarydetail(Long id) {
        return mapper.findSystemdictionarydetail(id);
    }

    @Override
    public void removeAllType(Long id) {
        List<Long> ids = new ArrayList<>();
        List<Systemdictionarydetail> list = Systemdictionarydetailmapper.findAll();
        for (Systemdictionarydetail systemdictionarydetail : list) {
            if(id.equals(systemdictionarydetail.getTypesId())){
                System.out.println(systemdictionarydetail.getTypesId());
                ids.add(systemdictionarydetail.getId());
            }
        }
        Systemdictionarydetailmapper.deleteByAll(ids);
        mapper.remove(id);
    }
}
